package com.tarena.lbs.coupon.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tarena.lbs.base.protocol.pager.BasePageQuery;
import com.tarena.lbs.coupon.dao.mapper.CouponMapper;
import com.tarena.lbs.coupon.dao.repository.CouponRepository;
import com.tarena.lbs.coupon.pojo.po.CouponPO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;


@Slf4j
@Repository
public class CouponRepositoryImpl implements CouponRepository {

    @Autowired
    private CouponMapper couponMapper;

    @Override
    public Page<CouponPO> getCouponListByBusinessId(BasePageQuery pageQuery,Integer businessId) {
        //创建分页对象
        Page<CouponPO> couponPOPage = new Page<>(pageQuery.getPageNo(), pageQuery.getPageSize());
        //构建查询条件
        QueryWrapper<CouponPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("business_id", businessId);
        //执行分页查询
        return couponMapper.selectPage(couponPOPage,queryWrapper);
    }

    @Override
    public void insertCoupon(CouponPO couponPO) {
        couponMapper.insert(couponPO);
    }

    @Override
    public CouponPO getCouponById(Integer id) {
        return couponMapper.selectById(id);
    }

    @Override
    public void deleteCoupon(Integer id) {
        couponMapper.deleteById(id);
    }

    @Override
    public void updateCoupon(CouponPO couponPO) {
        couponMapper.updateById(couponPO);
    }
}
